package com.lanqiao.guimei.controller;

import com.lanqiao.guimei.dao.AdminDao;
import com.lanqiao.guimei.vo.Admin;
import com.lanqiao.web.mvc.annotation.Controller;
import com.lanqiao.web.mvc.annotation.RequestMapping;
import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 韩原
 * @date 2019/8/13  16:52
 */
@Controller
public class AdminController {
    Logger logger = Logger.getLogger(AdminController.class);

    /**
     * 后台登录
     * @param session
     * @param admin
     * @return
     */
    @RequestMapping("/Admin/login")
    public String adminlogin(HttpSession session, Admin admin) {
        // 默认，请求转发: /success.jsp
        // 重定向：redirect:/success.jsp
        Admin logAdmin = new AdminDao().login(admin);
        System.out.println(logAdmin);
        if (logAdmin != null) {
            session.setAttribute("logAdmin", logAdmin);
            // 重定向
            return "/after/index.jsp";
        } else {
            return "/after/managerlogin.jsp";
        }
    }

    /**
     * 管理员修改密码
     * @param request
     * @param session
     * @param admin
     * @return
     */
    @RequestMapping("/admin/update")
    public Map adminupdate(HttpServletRequest request, HttpSession session, Admin admin){

        String oldpwd = request.getParameter("oldPassword");
        Admin admin1 =new AdminDao().findly(admin);
        Boolean b = new AdminDao().update(admin,admin1,oldpwd);
        if (b) {
            Map json = new HashMap();
            json.put("result", b);
            return json;
        }else {
            Map json = new HashMap();
            json.put("result", b);
            return json;
        }
    }


}
